realpath() {
  cd "$1" >/dev/null && pwd -P
}


assert_installed() {
  if ! [ -x "$(command -v $1)" ]; then
    echo "Error: $1 is not installed, try following command" >&2
    echo "$2" >&2
    exit 1
  fi
}

panic() {
  echo "$@"
  exit 1
}

list_go_mod() {
  find . -name go.mod ! -path ./vendor/\* -type f
}

list_cli() {
  while read -r main
  do
    main=${main%/main.go}
    main=${main#cmd/}
    echo $main
  done < <(find cmd/cli -name main.go -type f)
}

# https://stackoverflow.com/a/61295744
shopt -s expand_aliases
alias trace_on='set -x'
alias trace_off='{ PREV_STATUS=$? ; set +x; } 2>/dev/null; (exit $PREV_STATUS)'
